home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Fields_crop.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  3.3 KB  |  133 lines

  1. /*
  2. ** $VER: Fields_crop.ieb 1.11, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 1/2 1997 Stockholm/Sweden
  6. **
  7. ** Crop image into a serie of small images.
  8. */
  9.  
  10. options results
  11. signal on error
  12.  
  13. parse arg input command
  14. input = upper(strip(input))
  15. address 'IMAGEENGINEER'
  16.  
  17. select  /* Required batch script commands */
  18.   when input = 'INFO' then    return get_info()
  19.   when input = 'CONFIG' then  return get_config(command)
  20.   when input = 'PROCESS' then return process_image(command)
  21.   otherwise do
  22.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  23.     return '<ERROR>'
  24.   end
  25. end
  26.  
  27. exit 0
  28.  
  29. /* Required "Get_info" procedure  ------------------------------------ */
  30. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  31.  
  32. get_info:
  33.   back = 'OK'
  34. return back
  35.  
  36. /* Required "Get_config" procedure  ---------------------------------- */
  37.  
  38. get_config:
  39.   parse arg '"'command'"'
  40.  
  41.   Xfield=64 ; Yfield=64
  42.  
  43.   if command ~= '' then parse var command Xfield Yfield
  44.  
  45.   'IE_TO_FRONT'
  46.  
  47.   'FORM "Fields Crop" " OK | Cancel "',
  48.   ' INTEGER,"Field size width (X)",2,1024,'Xfield',SLIDER',
  49.   ' INTEGER,"Field size height (Y)",2,1024,'Yfield',SLIDER'
  50.  
  51.   parse var result ok Xfield Yfield .
  52.   if ok = 0 then return '<ERROR>'
  53.  
  54.   back = Xfield Yfield
  55. return back
  56.  
  57. /* Required "Process_image" procedure  ------------------------------- */
  58.  
  59. process_image:
  60.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  61.   parse var options Xfield Yfield .
  62.  
  63.   'OPEN' '"'src_image'"' '24'
  64.   if (RC ~= 0) then do
  65.     'IE_TO_FRONT'
  66.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  67.     return '<ERROR>'
  68.   end
  69.   else LoadImage = result
  70.  
  71.   'PROJECT_INFO' LoadImage 'WIDTH'  /* image width */
  72.   IW = RESULT
  73.   'PROJECT_INFO' LoadImage 'HEIGHT' /* image height */
  74.   IH = RESULT
  75.  
  76.   im_nr = 0
  77.  
  78.   do y = 1 to trunc(IH/Yfield)+1
  79.     do x = 1 to trunc(Xfield)+1
  80.  
  81.       CropX = trunc((x-1)*Xfield)
  82.       CropY = trunc((y-1)*Yfield)
  83.       CropXX = trunc(x*Xfield)-1
  84.       CropYY = trunc(y*Yfield)-1
  85.  
  86.       if CropXX >= IW then CropXX = IW-1
  87.       if CropYY >= IH then CropYY = IH-1
  88.       if CropXX <= CropX then leave
  89.       if CropYY <= CropY then leave
  90.  
  91.       'CROP' LoadImage CropX CropY CropXX CropYY
  92.       CropImage = Result
  93.  
  94.       im_nr = im_nr + 1
  95.  
  96.       if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  97.       'SAVE_DATA' CropImage '"'dst_image'.'right(im_nr,4,'0')'"' '"'getclip('cfg_save_frmt')'"'
  98.       if (RC ~= 0) then do
  99.         'IE_TO_FRONT'
  100.         'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  101.         return '<ERROR>'
  102.       end
  103.       'CLOSE' CropImage
  104.  
  105.     end /* Xfield */
  106.   end /* Yfield */
  107.  
  108.   'CLOSE' LoadImage
  109.  
  110.   back = 'OK'
  111. return back
  112.  
  113. /* Internal procedures  ---------------------------------------------- */
  114.  
  115. /*******************************************************************/
  116. /* This is where control goes when an error code is returned by IE */
  117. /* It puts up a message saying what happened and on which line     */
  118. /*******************************************************************/
  119.  
  120. error:
  121. if RC=5 then do
  122.     IE_TO_FRONT
  123.     LAST_ERROR
  124.     'REQUEST "'||RESULT||'"'
  125. end
  126. else do
  127.     IE_TO_FRONT
  128.     LAST_ERROR
  129.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  130. end
  131.  
  132. return '<ERROR>'
  133.